from pydantic import BaseModel, Field
from typing import List, Optional, Dict, Any, Union
from datetime import date

# --- 请求参数模型 ---

class StatisticsParams(BaseModel):
    """统计接口的查询参数模型"""
    metrics: Optional[List[str]] = Field(None, description="需要查询的指标集合, e.g., ['summary', 'by_college']")
    group_by: Optional[List[str]] = Field(None, description="分组维度, e.g., ['college_name', 'grade_name']")
    start_time: Optional[date] = Field(None, description="统计开始时间")
    end_time: Optional[date] = Field(None, description="统计结束时间")
    school_id: Optional[int] = Field(None, description="学校ID")
    college_name: Optional[str] = Field(None, description="学院名称")
    grade_name: Optional[str] = Field(None, description="年级名称")
    major_name: Optional[str] = Field(None, description="专业名称")
    education_level: Optional[str] = Field(None, description="培养层次")
    campus_name: Optional[str] = Field(None, description="校区名称")
    academic_year_name: Optional[str] = Field(None, description="学年")
    term_code: Optional[str] = Field(None, description="学期")
    courseType: Optional[str] = Field(None, description="课程类型")


# --- 响应数据模型 ---

class SummaryStats(BaseModel):
    """总量统计"""
    schools: int = 0
    classes: int = 0
    courses: int = 0
    users: int = 0
    system_logs: int = 0

class ByCollegeStat(BaseModel):
    """按学院统计"""
    college_name: str
    class_count: int = 0
    course_count: int = 0
    student_total: int = 0

class ByGradeStat(BaseModel):
    """按年级统计"""
    grade_name: str
    class_count: int = 0
    course_count: int = 0
    student_total: int = 0

class BySchoolCourseStat(BaseModel):
    """按学校统计课程"""
    school_id: int
    school_name: str
    course_count: int

class StatisticsResponseData(BaseModel):
    """统计接口返回的数据体"""
    summary: Optional[SummaryStats] = None
    by_college: Optional[List[ByCollegeStat]] = None
    by_grade: Optional[List[ByGradeStat]] = None
    by_school_course_count: Optional[List[BySchoolCourseStat]] = None

class StatisticsResponse(BaseModel):
    """统计接口的完整响应模型"""
    code: int = 200
    message: str = "success"
    data: StatisticsResponseData
